﻿@page "/Base_Manage/Base_Action/List"

@inherits BaseListWithEdit<Base_ActionTree, EditForm>

<Space Size="@("small")">

    @if (Operator.HasPerm("Base_Action.Add"))
    {
        <SpaceItem>
            <Button Type="@ButtonType.Primary" Icon="plus" OnClick="()=>Edit()">新建</Button>
        </SpaceItem>
    }
    @if (Operator.HasPerm("Base_Action.Delete"))
    {
        <SpaceItem>
            <Popconfirm Title="确认删除选中项吗?"
                    OnConfirm="()=>Delete()"
                    OnCancel="()=>{}"
                    OkText="确定"
                    CancelText="取消"
                    Disabled=@NoneSelectedItems>
                <Button Type="@ButtonType.Primary" Danger Icon="minus" Disabled=@NoneSelectedItems>删除</Button>
            </Popconfirm>
        </SpaceItem>
    }
    <SpaceItem>
        <Button Type="@ButtonType.Primary" Icon="reload" OnClick="()=>Refresh()" >刷新</Button>
    </SpaceItem>
</Space>

<Table @ref="_table"
       TItem="Base_ActionTree"
       DataSource="Data"
       EnableVirtualization
       TreeChildren="item=>item.Children"
       DefaultExpandAllRows
       Loading="Loading"
       HidePagination
       PageSize="Pagination.PageRows"
       @bind-SelectedRows="SelectedItems"
       ScrollX="1600"
       ScrollBarWidth="12px"
       Size="TableSize.Small"
       RowClassName="@(x => x.RowIndex % 2 == 0 ?"gray-2":"")">
    <ChildContent>
        <Selection Key="@(context.Id)" />
        <AntDesign.Column Title="菜单名" DataIndex="Text" TData="string" />
        <AntDesign.Column Title="类型" DataIndex="TypeText" TData="string" />
        <AntDesign.Column Title="路径" DataIndex="Url" TData="string" />
        <AntDesign.Column Title="需要权限" DataIndex="NeedActionText" TData="string" />
        <AntDesign.Column Title="页面权限" TData="string">
            @if (@context.PermissionValues != null)
            {  @foreach (var item in context.PermissionValues)
                {
                    var color = "geekblue";
                    if (item.Contains("Add"))
                    {
                        color = "green";
                    }
                    else if (item.Contains("Delete"))
                    {
                        color = "volcano";
                    }
                    <Tag Color="@color">@item</Tag>
                }
            }
        </AntDesign.Column>
        <AntDesign.Column Title="图标" TData="string">
            <Icon Type="@context.Icon" Theme="outline" />
        </AntDesign.Column>
        <AntDesign.Column Title="排序" DataIndex="Sort" TData="int" />
        <ActionColumn Title="Action" Fixed="right">
            <Space Size=@("small")>
                <SpaceItem>
                    <Button Type="@ButtonType.Link" Style="padding:0px" OnClick="()=>Edit(context)">Edit</Button>
                    <Popconfirm Title="确认删除吗?"
                                OnConfirm="()=>Delete(context.Id)"
                                OnCancel="()=>{}"
                                OkText="确定"
                                CancelText="取消">
                        <Button Danger Type="@ButtonType.Link" Style="padding:0px">Delete</Button>
                    </Popconfirm>
                </SpaceItem>
            </Space>
        </ActionColumn>
    </ChildContent>
</Table>

<style>
    .gray-2 {
        background-color: #fafafa;
    }
</style>

@code
{
    public List()
    {
        Area = "Base_Manage";
        GetDataList = "GetMenuTreeList";
        NewTitle = "新建权限";
        EditTitle = "编辑权限";
        Pagination.PageRows = Int32.MaxValue;
    }
}